import Vue from "vue";
import VueRouter from "vue-router";
import UserAbout from "@/components/front/UserAbout.vue";
import UserDetail from "@/views/front/UserDetail.vue";
import Register from "@/views/Register.vue";
import UserOrder from "@/views/front/UserOrder.vue";
import Cart from "@/views/front/Cart.vue";
import ReceiptAddress from "@/views/front/ReceiptAddress.vue";
import UserCollection from "@/views/front/UserCollection.vue";
import WaitEvaluate from "@/views/front/WaitEvaluate.vue";
import Search from "@/views/front/Search.vue";
import BookDetail from "@/views/front/BookDetail.vue";
import Catalogue from "@/views/front/Catalogue.vue";

Vue.use(VueRouter);

const Login = () => import("../views/Login.vue");
const Home = () => import("../views/front/Home.vue");

const routes = [
  {
    path: "/",
    redirect: "/home", // 设置根路径重定向到 /home
  },
  {
    path: "/home",
    name: "Home",
    component: Home,
    meta: {
      title: "主页",
    },
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
    meta: {
      title: "登录",
    },
  },
  //注册
  {
    path: "/register",
    name: "Register",
    component: Register,
    meta: {
      title: "注册",
    },
  },
  //搜索
  {
    path: "/search",
    name: "search",
    component: Search,
    meta: {
      title: "阅淘网",
    },
  },
  //目录
  {
    path: "/catalogue",
    name: "catalogue",
    component: Catalogue,
    meta: {
      title: "阅淘网",
    },
  },
  //书籍详情
  {
    path: "/product-detail",
    name: "书籍详情",
    component: BookDetail,
    meta: {
      title: "悦淘网",
    },
  },
  //用户相关
  {
    path: "/user-about",
    component: UserAbout,
    meta: {
    },
    children: [
      {
        //用户个人信息
        path: "user-detail",
        component: UserDetail,
        meta: {
          title: "个人信息",
        },
      },
      {
        //用户购物车
        path: "cart",
        component: Cart,
        meta: {
          title: "我的购物车",
        },
      },
      {
        //收货地址
        path: "receipt-address",
        component: ReceiptAddress,
        meta: {
          title: "收货地址",
        },
      },
      {
        //用户收藏
        path: "user-collection",
        component: UserCollection,
        meta: {
          title: "我的收藏",
        },
      },
      {
        //待评价
        path: "wait-evaluate",
        component: WaitEvaluate,
        meta: {
          title: "待评价",
        },
      },
      {
        //用户历史订单
        path: "order",
        component: UserOrder,
        meta: {
          title: "我的订单",
        },
      },
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});


export default router;
